package action.operate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;

import bean.Operation;

/*
 * 注册校验
 */
public class RegisterCheck {
	public String execute() {
		// 得到HttpSession方法
		HttpSession session = ServletActionContext.getRequest().getSession();
		// 得到HttpServletRequest方法
		HttpServletRequest request = ServletActionContext.getRequest();

		// 判断用户是否登录
		if ("true".equals(session.getAttribute("login"))) {
			return "home";
		} else {
			String username = request.getParameter("username"), password = request.getParameter("password"),
					tel = request.getParameter("tel"), email = request.getParameter("email");

			Operation operation = new Operation();
			try{
			if (operation.register(username, password, email, tel)) {
				return "login";
			} else {
				request.setAttribute("register", "false");
				return "register";
			}
			}catch(Exception e){
				return "registerAction";
			}
		}
	}
}
